package com.cctv.custom.hibernate.integrated.wrapper;

import java.util.List;

import org.testng.annotations.Test;

public class BookServiceTest3 extends BasicTest {

	@Test
	public void testGetPackageBooks() {
		BookService bookService = context.getBean(BookService.class);
		Book book = new Book();
		Book book2 = new Book();
		Book book3 = new Book();
		Book book4 = new Book();

		book.setName("Java");
		book2.setName("Java");
		book3.setName("ASP.NET");
		book4.setName("C++");

		book.setAuthor("Ice");
		book2.setAuthor("apache");
		book3.setAuthor("tony");
		book4.setAuthor("bear");

		book.setPrice(10.0);
		book2.setPrice(8.0);
		book3.setPrice(1.0);
		book4.setPrice(15.0);

		bookService.saveOrUpdate(book);
		bookService.saveOrUpdate(book2);
		bookService.saveOrUpdate(book3);
		bookService.saveOrUpdate(book4);

		List<Book> list = bookService.list(null, 0, 3);
		assert list.size() == 3;
		assert list.get(0).getAuthor().equals("bear");
		assert list.get(1).getAuthor().equals("Ice");
		assert list.get(2).getAuthor().equals("apache");

		List<Book> list2 = bookService.list(null, 1, 3);
		assert list2.size() == 1;
		assert list2.get(0).getAuthor().equals("tony");

		assert bookService.list(null, 2, 3).size() == 0;

		assert bookService.list(null, 0, 5).size() == 4;
	}
}
